package org.example;

import org.example.config.MyAppConfig;
import org.example.controller.LoginController;
import org.example.controller.URLController;
import org.example.model.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
    public static void main(String[] args) {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("beans.xml");

        System.out.println(context.getBean(LoginController.class)==context.getBean(LoginController.class));






//         context.getBean(LoginController.class).sayHi();




        //        通过@Configuration注解注入
//        System.out.println(context.getBean(MyAppConfig.class));



        //通过@Controller注解注入
//        LoginController loginController =
//                (LoginController) context.getBean("loginController");
//        System.out.println(loginController);
//        URLController urlController =
//                (URLController) context.getBean("URLController");
//        System.out.println(urlController);

//        LoginController loginController2 =
//                context.getBean(LoginController.class);
//        System.out.println(loginController2);

        //src\main\java\org\example\controller\LoginController.java
//        User user1 = (User) context.getBean("user1");
//        System.out.println(user1);
//        System.out.println(context.getBean("user2", User.class));//无需强转


        // 关闭资源
        ((ClassPathXmlApplicationContext) context).close();

    }
}
